//
//  SCAboutController.m
//  Scalper
//
//  Created by 王云 on 2017/9/30.
//  Copyright © 2017年 WY. All rights reserved.
//

#import "SCAboutController.h"
#import <WebKit/WebKit.h>

@interface SCAboutController ()<WKUIDelegate,WKNavigationDelegate>

@property (nonatomic,weak)WKWebView *webView;

@end

@implementation SCAboutController

- (void)viewDidLoad {
    [super viewDidLoad];

//    self.title = @"关于我们";

    self.view.backgroundColor = [UIColor whiteColor];
    
//    [self.navigationController.navigationBar lt_setBackgroundColor:[UIColor whiteColor]];
//    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
//    textAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];
//    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:16];
//    [self.navigationController.navigationBar setTitleTextAttributes:textAttrs];
//    UIBarButtonItem *backLfet = [UIBarButtonItem itemWithIcon:@"good_arrow_yellow" highIcon:@"good_arrow_yellow" target:self action:@selector(back)];
//    self.navigationItem.leftBarButtonItem = backLfet;
    
    
    [self.view addSubview:self.webView];
    
    NSString *urlStr;
    if ([_type isEqualToString:@"HelpAccount"]) {
        urlStr = [[SCWebUrl stringByAppendingString:@"/faq_list.html?id=3&cname=账号（登录、密码等）&simple_mode=1"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }else{
        urlStr = [SCWebUrl stringByAppendingString:@"/about.html?simple_mode=1"];
    }
     NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
    [self.webView loadRequest:request];
    
    __weak __typeof(&*self)weakSelf = self;
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
    }];
}

- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    DLog(@"开始");
    [SCTool showLoading:@"正在加载"];
    
}
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
{
    DLog(@"返回数据");
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    self.title = webView.title;
    DLog(@"加载完成");
    [SCTool hideHUD];
    
}
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error{
    DLog(@"加载失败");
    [SCTool showError:@"加载失败"];
}

- (WKWebView *)webView{
    if (_webView == nil) {
        WKWebView *WebView = [[WKWebView alloc] initWithFrame:self.view.frame];
        WebView.UIDelegate = self;
        WebView.navigationDelegate = self;
        [self.view addSubview:WebView];
        _webView = WebView;
    }
    return _webView;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [SCTool hideHUD];
}


- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
